#ifndef QDEVICESERVER_H
#define QDEVICESERVER_H

#include <QObject>
#include <QUdpSocket>
#include <QDateTime>
#include <QTimer>

struct tagDeviceInfo;
struct tagServerInfo;

class QDeviceServer : public QObject
{
    Q_OBJECT
public:
    explicit QDeviceServer(tagServerInfo* info,QObject *parent = 0);
    ~QDeviceServer();

    void    search(int addr=-1);

    void    send_data(const QByteArray &data,int addr);
    tagServerInfo   *get_server_info();
signals:
    void    new_device(tagDeviceInfo *device);
    void    device_offline(const QString &uuid);
    void    recv_data(const QByteArray& data);
    void    property_refresh(const QString &uuid,const QStringList &list);
protected slots:
    void    read();
    void    send_read();

    void    hand_timer();
protected:
    tagServerInfo   *m_server_info;
    QUdpSocket      *m_socket;
    QUdpSocket      *m_recv_send_socket;
    QMap<QString,QDateTime>     m_device_hand;
    QTimer          *m_timer;
    QDateTime       m_last_date_time;
};

#endif // QDEVICESERVER_H
